//
//  ListAgreementsTableViewController.m
//  HYApp
//
//  Created by Jianbo Cai on 2020/8/21.
//  Copyright © 2020 Unidax. All rights reserved.
//

#import "ListAgreementsTableViewController.h"
#import "TermServiceViewController.h"
#import "HYNetHelper.h"

@interface ListAgreementsTableViewController ()
AWPMutArray(dataSource)
@end

@implementation ListAgreementsTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.tableFooterView = [[UIView alloc]init];
    self.tableView.separatorInset = UIEdgeInsetsZero;
    self.navigationItem.title =  JFMainLocalizedString(@"myProfile.SignedAgreements");
    //獲取已經簽署的協議
    WEAKSELF
    [HYNetHelper singedAgreements:^(JFResultVo *resultVo) {
        if (resultVo.errorNo == 0) {//設置
            NSArray * data = resultVo.results[@"data"];
            if (data && data.count) {
                [weakSelf.dataSource removeAllObjects];
                [weakSelf.dataSource addObjectsFromArray:data];
            }
        }
        [weakSelf.tableView reloadData];
    }];
    
    
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self initLanguage];
}
-(void)initLanguage{
    
}

#pragma mark - Table view data source
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"asdsssss"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"asdsssss"];
    }
    cell.textLabel.AWfont(JFPingFangFont(16)).AWtextColorQ(@"#333333");
    cell.detailTextLabel.AWfont(JFPingFangFont(13)).AWtextColorQ(@"#999999");
    if(indexPath.row < self.dataSource.count){
        NSDictionary * dict  = self.dataSource[indexPath.row];
        cell.textLabel.text = dict[@"name"];
        NSString * signed_date = dict[@"signed_date"];
        cell.detailTextLabel.text = [[signed_date componentsSeparatedByString:@" "] firstObject];
    }
    UIImageView *viewArrow = [[UIImageView alloc] init];
    viewArrow.frameSize = CGSizeMake(6, 11);
    viewArrow.backgroundColor = [UIColor clearColor];
    viewArrow.image = [UIImage imageNamed:@"right_icon"];
    cell.accessoryView = viewArrow;
    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(nonnull NSIndexPath *)indexPath
{
    TermServiceViewController *vc = [[UIStoryboard storyboardWithName:@"User" bundle:nil]instantiateViewControllerWithIdentifier:@"TermServiceViewController"];;
    NSDictionary * dict  = self.dataSource[indexPath.row];
    vc.dict = dict;
    [self.navigationController pushViewController:vc animated:YES];
}

AWLazyGetMethodWithBlock(NSMutableArray, dataSource, {})

@end
